package utilities;

import java.util.Random;

public class PasswordGenerator {

	private String currentPassword;
	private String generatedPassword;
	Random random = new Random();
	private char[] lowCaseLet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
								 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
	private char[] upCaseLet = 	{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
								 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
	private char[] numbers = 	{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
	private char[] specChars = 	{'.', '-', '_', '+', '!', '?', '='};
	
	public String getNewPassword() {
		
		generatedPassword = "12345678";			// Give a beginning value
		generatedPassword = generatedPassword.replace('1', lowCaseLet[random.nextInt(lowCaseLet.length-1) ]);
		generatedPassword = generatedPassword.replace('2', upCaseLet[random.nextInt(upCaseLet.length-1)	 ]);
		generatedPassword = generatedPassword.replace('3', numbers[random.nextInt(numbers.length-1)	 ]);
		generatedPassword = generatedPassword.replace('4', specChars[random.nextInt(specChars.length-1)	 ]);
		generatedPassword = generatedPassword.replace('5', lowCaseLet[random.nextInt(lowCaseLet.length-1) ]);
		generatedPassword = generatedPassword.replace('6', upCaseLet[random.nextInt(upCaseLet.length-1)	 ]);
		generatedPassword = generatedPassword.replace('7', numbers[random.nextInt(numbers.length-1)	 ]);
		generatedPassword = generatedPassword.replace('8', specChars[random.nextInt(specChars.length-1)	 ]);
		
		currentPassword = generatedPassword;
		// burde lave en scramble metode??
		return currentPassword;
	}
	
	public String getLastPassword() {
		if(currentPassword != null) { return currentPassword; }
		else
		{ return getNewPassword(); }
	}
}
